home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Lose Your Marbles! 1.0 / source / Shell ƒ / about MSG.c next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  6.8 KB  |  253 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        about MSG.c
  4.  
  5. Purpose:    This module handles displaying the "About MSG" splash
  6.             screen.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "about MSG.h"
  26. #include "environment.h"
  27. #include "sounds.h"
  28.  
  29. extern Point RawMouse : 0x82C;
  30.  
  31. /*-----------------------------------------------------------------------------------*/
  32. /* internal stuff for about MSG.c                                                    */
  33.  
  34. void SetupTheAboutMSGWindow(WindowDataHandle theData);
  35. void OpenTheMSGWindow(WindowDataHandle theData);
  36. void DrawTheAboutMSGWindow(void);
  37. void DoTheMSGThing(WindowDataHandle theData);
  38. void ActivateTheMSGWindow(void);
  39. void DeactivateTheMSGWindow(WindowDataHandle theData);
  40. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine);
  41. void DrawTheAboutString(Str255 theString, short theWidth, short *theRow);
  42. void DrawTheCarpet(void);
  43. void DrawTheString(Str255 theString, short theWidth, short* theRow);
  44. void DrawCarpet(short x, short y, short len);
  45.  
  46. static short        gOldForegroundTime;
  47.  
  48. short AboutMSGBoxDispatch(WindowDataHandle theData, short theMessage, unsigned long misc)
  49. {
  50.     short            theDepth;
  51.     
  52.     switch (theMessage)    /* see graphics.h for list of messages*/
  53.     {
  54.         case kNull:
  55.             if (!gIsInBackground)
  56.                 DoTheMSGThing(theData);
  57.             return kSuccess;
  58.             break;
  59.         case kUpdate:
  60.             DrawTheAboutMSGWindow();
  61.             return kSuccess;
  62.             break;
  63.         case kOpen:
  64.             OpenTheMSGWindow(theData);
  65.             return kSuccess;
  66.         case kActivate:
  67.             ActivateTheMSGWindow();
  68.             return kSuccess;
  69.             break;
  70.         case kDeactivate:
  71.             DeactivateTheMSGWindow(theData);
  72.             return kSuccess;
  73.             break;
  74.         case kKeydown:                            /* close about box on keypress */
  75.         case kMousedown:                        /* or mouseclick */
  76.             CloseTheWindow((ExtendedWindowDataHandle)theData);
  77.             return kSuccess;
  78.             break;
  79.         case kStartup:
  80.             SetupTheAboutMSGWindow(theData);
  81.             return kSuccess;
  82.             break;
  83.     }
  84.     
  85.     return kFailure;        /* for all other messages, defer to default processing */
  86. }
  87.  
  88. void SetupTheAboutMSGWindow(WindowDataHandle theData)
  89. {
  90.     (**theData).windowWidth=243;
  91.     (**theData).windowHeight=243;
  92.     (**theData).windowType=plainDBox;        /* plain rectangle */
  93.     (**theData).windowTitle[0]=0x00;        /* null title, never shown */
  94.     (**theData).hasCloseBox=FALSE;
  95.     (**theData).maxDepth=1;
  96. }
  97.  
  98. void OpenTheMSGWindow(WindowDataHandle theData)
  99. {
  100.     long            dummy;
  101.     
  102.     DoSound(sound_aboutMSG, TRUE);
  103.     UpdateTheWindow((ExtendedWindowDataHandle)theData);
  104.     Delay(30, &dummy);
  105. }
  106.  
  107. void ActivateTheMSGWindow(void)
  108. {
  109.     gOldForegroundTime=gForegroundWaitTime;
  110.     gForegroundWaitTime=0;
  111. }
  112.  
  113. void DeactivateTheMSGWindow(WindowDataHandle theData)
  114. {
  115.     UpdateTheWindow((ExtendedWindowDataHandle)theData);
  116.     gForegroundWaitTime=gOldForegroundTime;
  117. }
  118.  
  119. void DoTheMSGThing(WindowDataHandle theData)
  120. {
  121.     Rect            sourceRect, destRect;
  122.     Rect            mainRect;
  123.     long            lr,tb;
  124.     short            l,t;
  125.     short            index;
  126.     
  127.     index=(**theData).windowIndex;
  128.     mainRect=screenBits.bounds;
  129.     if (PtInRect(RawMouse, &mainRect))
  130.     {
  131.         lr=RawMouse.h-mainRect.left;
  132.         lr*=81;
  133.         lr/=mainRect.right-mainRect.left;
  134.         tb=RawMouse.v-mainRect.top;
  135.         tb*=81;
  136.         tb/=mainRect.bottom-mainRect.top;
  137.         if (tb<0)
  138.             tb=0;
  139.         l=RawMouse.h-lr;
  140.         t=RawMouse.v-tb;
  141.         SetRect(&sourceRect, l, t, l+81, t+81);
  142.         SetRect(&destRect, 81, 81, 162, 162);
  143.         SetPort(GetIndWindowGrafPtr(index));
  144.         CopyBits(&(WMgrPort->portBits), &(GetIndWindowGrafPtr(index)->portBits),
  145.             &sourceRect, &destRect, 0, 0L);
  146.     }
  147. }
  148.  
  149. void DrawTheAboutMSGWindow(void)
  150. {
  151.     short            row;
  152.     Rect            sourceRect, destRect;
  153.     GrafPtr            curPort;
  154.     short            theWidth;
  155.     
  156.     GetPort(&curPort);
  157.     EraseRect(&(curPort->portRect));
  158.     theWidth=curPort->portRect.right-curPort->portRect.left;
  159.     
  160.     DrawCarpet(9,234,3);
  161.     SetRect(&sourceRect, 0, 216, 27, 243);
  162.     destRect=sourceRect;
  163.     OffsetRect(&destRect, 27, 0);
  164.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  165.         &sourceRect, &destRect, 0, 0L);
  166.     OffsetRect(&destRect, -27, -27);
  167.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  168.         &sourceRect, &destRect, 0, 0L);
  169.     OffsetRect(&destRect, 0, -27);
  170.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  171.         &sourceRect, &destRect, 0, 0L);
  172.     OffsetRect(&destRect, 27, 0);
  173.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  174.         &sourceRect, &destRect, 0, 0L);
  175.     SetRect(&sourceRect, 0, 162, 27, 243);
  176.     destRect=sourceRect;
  177.     OffsetRect(&destRect, 54, 0);
  178.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  179.         &sourceRect, &destRect, 0, 0L);
  180.     SetRect(&sourceRect, 0, 162, 81, 243);
  181.     destRect=sourceRect;
  182.     OffsetRect(&destRect, 81, 0);
  183.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  184.         &sourceRect, &destRect, 0, 0L);
  185.     OffsetRect(&destRect, -81, -81);
  186.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  187.         &sourceRect, &destRect, 0, 0L);
  188.     OffsetRect(&destRect, 0, -81);
  189.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  190.         &sourceRect, &destRect, 0, 0L);
  191.     OffsetRect(&destRect, 81, 0);
  192.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  193.         &sourceRect, &destRect, 0, 0L);
  194.     SetRect(&sourceRect, 0, 0, 81, 243);
  195.     destRect=sourceRect;
  196.     OffsetRect(&destRect, 162, 0);
  197.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  198.         &sourceRect, &destRect, 0, 0L);
  199.     
  200.     TextFont(geneva);
  201.     TextSize(9);
  202.     TextMode(srcXor);
  203.     row=92;
  204.     DrawTheString("\pMerriMac", theWidth, &row);
  205.     DrawTheString("\pSoftware", theWidth, &row);
  206.     DrawTheString("\pGroup ’94", theWidth, &row);
  207.     DrawTheString("\p", theWidth, &row);
  208.     DrawTheString("\pStill enhancing", theWidth, &row);
  209.     DrawTheString("\pthe flavor of", theWidth, &row);
  210.     DrawTheString("\pyour Macintosh.", theWidth, &row);
  211. }
  212.  
  213. void DrawTheString(Str255 theString, short theWidth, short* theRow)
  214. {
  215.     MoveTo((theWidth-StringWidth(theString))/2, *theRow);
  216.     DrawString(theString);
  217.     *theRow+=11;
  218. }
  219.  
  220. void DrawCarpet(short x, short y, short len)
  221. {
  222.     Rect            box;
  223.     short            iter;
  224.  
  225.     x-=len*2;
  226.     y+=len*2;
  227.     for (iter=0; iter<8; iter++)
  228.     {
  229.         box.left=x-len;
  230.         box.right=x+2*len;
  231.         box.top=y-2*len;
  232.         box.bottom=y+len;
  233.         FillRect(&box, black);
  234.         if (len>1) DrawCarpet(x,y,len/3);
  235.         box.left=x;
  236.         box.right=x+len;
  237.         box.bottom=y;
  238.         box.top=y-len;
  239.         FillRect(&box, white);
  240.         switch (iter)
  241.         {
  242.             case 0:
  243.             case 1: x+=len*3; break;
  244.             case 2:
  245.             case 3: y-=len*3; break;
  246.             case 4:
  247.             case 5: x-=len*3; break;
  248.             case 6:
  249.             case 7: y+=len*3; break;
  250.         }
  251.     }
  252. }
  253.